﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using connect;
using System.Collections;

namespace Pharmacy_management_system
{
    class chufangchaxufp
    {
        public string Querycondition(string sqlyuj2, RichTextBox[] rtb1, DateTimePicker[] dtp1,RadioButton[] rb1,LinkLabel[] ll1,CheckBox[] cb1)
        {
            string keshi, zhenduan, yisheng, yaopin;
            ArrayList any = new ArrayList();
        keshi = Connect.baozhuang(Connect.yy(rtb1[0].Text, any), "a.dept_name");
        zhenduan = Connect.baozhuang(Connect.yy(rtb1[2].Text, any), "a.diagnosis");
        yisheng = Connect.baozhuang(Connect.yy(rtb1[1].Text, any), "a.doctor_name");
        yaopin = Connect.baozhuang(Connect.yy(rtb1[3].Text, any), "b.order_text");
            string tiaojian = "";
            string brname = "";
            string brmenzhenhao = "";
            if (rtb1[4].Text.Trim() != "")
            {
                brname = Connect.baozhuang(Connect.yy(rtb1[4].Text.Trim().ToString(), any), "a.patient_name");
            }
            if (rtb1[5].Text.Trim() != "")
            {
                brmenzhenhao = Connect.baozhuang(Connect.yy(rtb1[5].Text.Trim().ToString(), any), "a.inp_no");
            }
            string starttime = dtp1[0].Text.ToString();
            string endtime = dtp1[1].Text.ToString();
            if (rb1[0].Checked)
            {
                tiaojian += "and a.case_id like 'mz%'";
            }
            else { tiaojian += "and a.case_id like 'zy%'"; }
            if (ll1[5].Visible == false)
            {
                if (cb1[0].Checked)
                {
                    string c = "";
                    if (cb1[2].Checked)
                        c = " and a.cf_level='0' ";
                    else
                    {
                        c = "and (1=2";
                        if (cb1[3].Checked)
                        {
                            c += " or a.cf_level='3'";
                        }
                        if (cb1[4].Checked)
                        {
                            c += " or a.cf_level='2'";
                        }
                        if (cb1[5].Checked)
                        {
                            c += " or a.cf_level='1'";
                        }
                        c += ") ";
                    }
                    tiaojian += " and a.cf_time between '" + dtp1[6].Text.Trim().ToString() + "' and '" + dtp1[7].Text.Trim().ToString() + "' " + c;
                }
                if (cb1[7].Checked)
                {
                    string c = " ";
                    if (cb1[8].Checked)
                    {
                        c += " and a.wsq_level = '0' ";
                    }
                    if (cb1[9].Checked)
                    {
                        c += " and a.wsq_level ='1' ";
                    }
                    tiaojian += " and a.wsq_time between '" + dtp1[4].Text.ToString() + "' and '" + dtp1[5].Text.ToString() + "' " + c;
                }
                if (cb1[11].Checked)
                {
                    string c = "";
                    if (cb1[13].Checked)
                    {
                        c += " and a.zl_level ='0' ";
                    }
                    if (cb1[12].Checked)
                    {
                        c += " and a.zl_level='1' ";
                    }
                    tiaojian += " and a.zl_time between '" + dtp1[2].Text.ToString() + "' and '" + dtp1[3].Text.ToString() + "' " + c;
                }
                if (cb1[14].Checked)
                {
                    tiaojian += " and a.tiaobiao is not null and a.end_date between '" + dtp1[9].Text.ToString() + "' and '" + dtp1[8].Text.ToString() + "' ";
                }
                if (cb1[16].Checked)
                {
                    tiaojian += " and a.writer is not null and writertime between '" + dtp1[11].Text.ToString() + "' and '" + dtp1[10].Text.ToString() + "'";
                }

            }
            sqlyuj2 = "where 1=1 and start_date between '" + starttime + "' and  '" + endtime + "' " + brmenzhenhao + brname + keshi + zhenduan + yisheng + yaopin + tiaojian;
            return sqlyuj2;
        }
    }
}
